package com.aiwiown.snackmq.common.serialization;

import java.lang.reflect.Type;

/**
 * The core interface for all serialization strategies.
 * This is the final, complete version.
 */
public interface Serializer {

    /**
     * Returns the unique byte identifier for this serialization algorithm.
     * @return A byte representing the algorithm ID.
     */
    byte getAlgorithmId();

    /**
     * Serializes an object into a byte array.
     * @param obj The object to serialize.
     * @return The resulting byte array.
     */
    byte[] serialize(Object obj);

    /**
     * Deserializes a byte array into an object of the specified class.
     * @param data The byte array to deserialize.
     * @param clazz The target class.
     * @return The deserialized object.
     * @param <T> The type of the object.
     */
    <T> T deserialize(byte[] data, Class<T> clazz);

    /**
     * --- THE CRUCIAL FIX ---
     * This method was missing from the interface, causing the compilation error.
     * It deserializes a byte array into an object of a specific generic type.
     *
     * @param data The byte array to deserialize.
     * @param typeOfT The specific generic type (e.g., for a Map or List).
     * @return The deserialized object.
     * @param <T> The generic type.
     */
    <T> T deserialize(byte[] data, Type typeOfT);
}